package com.dq.domain.setup;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.org.Org;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @Author luchangtong
 * @Date 2019/11/20 14:56
 */
@Entity
@Data
@ApiModel("礼物发放设置")
public class GiftGrantSet extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("类别编号")
    protected String giftCategoryNo;
    @ApiModelProperty("类别名称")
    protected String categoryName;
    @ApiModelProperty("描述")
    protected String description;

    @ApiModelProperty("门店")
    @ManyToOne
    protected Org org;
    @ApiModelProperty("总数量")
    protected Long amount;
    @ApiModelProperty("剩余数量")
    protected Long stock;

    @Data
    @ApiModel(value = "礼物发放设置视图")
    public static class Vo implements VO {
        public Long id;
        @ApiModelProperty("类别编号")
        protected String giftCategoryNo;
        @ApiModelProperty("类别名称")
        protected String categoryName;
        @ApiModelProperty("描述")
        protected String description;
        @ApiModelProperty("门店名")
        protected String orgName;
        @ApiModelProperty("门店id")
        protected Long orgId;
        @ApiModelProperty("总数量")
        protected Long amount;
        @ApiModelProperty("剩余数量")
        protected Long stock;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id= this.getId();
        vo.giftCategoryNo = this.getGiftCategoryNo();
        vo.categoryName = this.getCategoryName();
        vo.description = this.getDescription();
        vo.orgId = this.getOrg()!= null ? this.getOrg().getId():null;
        vo.orgName = this.getOrg()!= null ?this.getOrg().getSimpleName():"";
        vo.amount = this.getAmount() != null ?this.getAmount():0L;
        vo.stock = this.getStock() != null ?getStock():0L;;

        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUsername();
        return vo;
    }
}
